﻿using SHomeWorkshop.LunarSF.StudentInfosManager;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DotNet.Utilities;
using System.Data.SQLite;
using System.Data;

namespace SHomeWorkshop.LunarSF.StudentInfosManager
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : MetroWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                this.cmbGradesCount.DataContext =
                this.tbxSchoolName.DataContext = settings;

                dbFilePath = Globals.PathOfUserFolder + "data.db";
                dbManager = new SQLiteDBManager(dbFilePath);
                if (dbManager.TableExist("StudentInfos") == false)
                {
                    using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbManager.DataBaseFilePath + ";Password=DyBj#PpBb;"))
                    {
                        connection.Open();
                        SQLiteCommand command = connection.CreateCommand();
                        command.CommandText =
                            "CREATE TABLE StudentInfos("
                            + "id                               INTEGER      PRIMARY KEY AUTOINCREMENT,"
                            + "StudentGrade	                    NTEXT        NOT NULL,"
                            + "StudentClass	                    NTEXT        NOT NULL,"
                            + "StudentNumber	                NTEXT        NOT NULL,"
                            + "StudentName	                    NTEXT        NOT NULL,"
                            + "StudentOldName	                NTEXT        NOT NULL,"
                            + "StudentCid	                    NTEXT        NOT NULL,"
                            + "SchoolRoll	                    NTEXT        NOT NULL,"
                            + "AdmissionDate                    NTEXT        NOT NULL,"
                            + "StudentNation	                NTEXT        NOT NULL,"
                            + "PoliticalStatus	                NTEXT        NOT NULL,"
                            + "NativePlace  	                NTEXT        NOT NULL,"
                            + "ResidencePlace	                NTEXT        NOT NULL,"
                            + "ResidenceType	                NTEXT        NOT NULL,"
                            + "StudentHealthCondition           NTEXT        NOT NULL,"
                            + "StudentCurrentPlace	            NTEXT        NOT NULL,"
                            + "StudentDetailAddress	            NTEXT        NOT NULL,"
                            + "StudentEmail	                    NTEXT        NOT NULL,"
                            + "PostCode	                        NTEXT        NOT NULL,"
                            + "StudentPhoneCode	                NTEXT        NOT NULL,"
                            + "GuardianName	                    NTEXT        NOT NULL,"
                            + "GuardianCompany	                NTEXT        NOT NULL,"
                            + "GuardianCid	                    NTEXT        NOT NULL,"
                            + "GuardianRelation	                NTEXT        NOT NULL,"
                            + "GuardianPhoneCode	            NTEXT        NOT NULL,"
                            + "SavingCardNumber                 NTEXT        NOT NULL,"
                            + "SavingCardBankName               NTEXT        NOT NULL,"
                            + "SavingCardOwnerName              NTEXT        NOT NULL,"
                            + "SavingCardOwnerRelationship      NTEXT        NOT NULL,"
                            + "SavingCardOwnerCid               NTEXT        NOT NULL,"
                            + "IsFiveGuaranteesFamily           NTEXT        NOT NULL,"
                            + "IsBasicLivingAllowances          NTEXT        NOT NULL,"
                            + "IsSingleParentChild              NTEXT        NOT NULL,"
                            + "IsOrphan                         NTEXT        NOT NULL,"
                            + "IsDeformityParentsChild          NTEXT        NOT NULL,"
                            + "StudentDeformityStatus           NTEXT        NOT NULL,"
                            + "IsParentsCanNotWork              NTEXT        NOT NULL,"
                            + "IsSeriousIllnessInTheFamily      NTEXT        NOT NULL,"
                            + "IsArmyOrSpecialCaredChild        NTEXT        NOT NULL,"
                            + "AnnualHouseholdIncome            NTEXT        NOT NULL,"
                            + "SourceOfFamilyIncome             NTEXT        NOT NULL,"
                            + "IsSufferFromNaturalDisasters     NTEXT        NOT NULL,"
                            + "NaturalDisastersDiscription      NTEXT        NOT NULL,"
                            + "IsUnexpectedAccidentHappened     NTEXT        NOT NULL,"
                            + "UnexpectedAccidentDiscription    NTEXT        NOT NULL,"
                            + "AmountOfDebt                     NTEXT        NOT NULL,"
                            + "DebtReson                        NTEXT        NOT NULL,"
                            + "FamilyMembersCount               NTEXT        NOT NULL,"
                            + "SupportPersonsCount              NTEXT        NOT NULL,"
                            + "IsRegistedPoorFamily             NTEXT        NOT NULL,"
                            + "IsRegistedBasicLivingAllowances  NTEXT        NOT NULL,"
                            + "OtherInfosFromCivilDepartment    NTEXT        NOT NULL,"
                            + "LaborCountOfFamily               NTEXT        NOT NULL,"
                            + "UnemployedCountOfFamily          NTEXT        NOT NULL,"
                            + "OtherInfos                       NTEXT        NOT NULL"
                            + ")";
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private string dbFilePath;

        SQLiteDBManager dbManager;

        private Settings settings = new Settings();

        private XmlConfigManager configManager = null;
        /// <summary>
        /// 用于保存配置的Xml配置管理器。
        /// </summary>
        public XmlConfigManager ConfigManager
        {
            get
            {
                if (this.configManager == null)
                {
                    this.configManager = new XmlConfigManager(Globals.PathOfUserFolder + "config.xml");
                }
                return configManager;
            }
        }

        private void settingsWizard_Finish(object sender, RoutedEventArgs e)
        {
            var manager = this.ConfigManager;

            settings.SaveToConfigManager(manager);
        }

        /// <summary>
        /// 是否所有必填的信息都已填写完毕，是否信息都符合格式，是否相关信息之间没有冲突。
        /// </summary>
        public string GetBaseInfosErrorText()
        {
            //StudentGrade      StudentClass        StudentNumber       StudentName
            //StudentOldName    StudentCid          SchoolRoll          AdmissionDate
            //StudentNation     PoliticalStatus     NativePlace         ResidencePlace
            //ResidenceType     StudentHealthCondi  StudentCurrentPlac  StudentDetailAddre
            //PostCode          StudentEmail        StudentPhoneCode    GuardianName
            //GuardianCompany   GuardianCid         GuardianPhoneCode
            return biiBaseInfosInputer.InfosEntry.BlankErrorText;
        }

        public int? GetYearFromCId(string cid)
        {
            if (string.IsNullOrWhiteSpace(cid)) return null;

            if (cid.Length == 15)
            {
                var yearText = cid.Substring(6, 2);
                int year;
                if (int.TryParse("19" + yearText, out year))
                {
                    return year;
                }
                else return null;
            }

            if (cid.Length == 18)
            {
                var yearText = cid.Substring(6, 4);
                int year;
                if (int.TryParse(yearText, out year))
                {
                    return year;
                }
                else return null;
            }

            return null;
        }

        private void studentInfosInputWizard_Next(object sender, Xceed.Wpf.Toolkit.Core.CancelRoutedEventArgs e)
        {
            if (studentInfosInputWizard.CurrentPage == wpBaseInfosInput)
            {
                int? studentBirthYear = GetYearFromCId(biiBaseInfosInputer.InfosEntry.StudentCid);
                int? guardianBirthYear = GetYearFromCId(biiBaseInfosInputer.InfosEntry.GuardianCid);
                if (studentBirthYear == null)
                {
                    LMessageBox.Show("　　学生身份证有误，无法读取出生年份。\r\n　　请修正后重试！", Globals.AppName,
                         MessageBoxButton.OK, MessageBoxImage.Error);
                    e.Cancel = true;
                    return;
                }

                if (guardianBirthYear == null)
                {
                    LMessageBox.Show("　　监护人身份证有误，无法读取出生年份。\r\n　　请修正后重试！", Globals.AppName,
                         MessageBoxButton.OK, MessageBoxImage.Error);
                    e.Cancel = true;
                    return;
                }

                if (guardianBirthYear.Value > studentBirthYear.Value)
                {
                    LMessageBox.Show("　　监护人出生年不能晚于学生出生年。\r\n　　请修正后重试！", Globals.AppName,
                         MessageBoxButton.OK, MessageBoxImage.Error);
                    e.Cancel = true;
                    return;
                }

                //国人的亲戚关系实在太复杂，下面这段代码明显有问题，不能用
                //例如：姑父、伯母……实在难以罗列清楚所有写法。
                //#region 根据监护人身份证号判断填写的关系是否正确
                //string s;
                //if (biiBaseInfosInputer.InfosEntry.GuardianCid.Length == 15)
                //{
                //    s = biiBaseInfosInputer.tbxGuardianCid.Text.Substring(13, 1);
                //}
                //else if (biiBaseInfosInputer.InfosEntry.GuardianCid.Length == 18)
                //{
                //    s = biiBaseInfosInputer.tbxGuardianCid.Text.Substring(13, 1);
                //}
                //else
                //{
                //    LMessageBox.Show("　　监护人身份证号错误！", Globals.AppName,
                //             MessageBoxButton.OK, MessageBoxImage.Error);
                //    e.Cancel = true;
                //    return;
                //}

                //int x;
                //if (int.TryParse(s, out x))
                //{
                //    var haveError = false;
                //    if (x % 2 == 0 && (
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("父") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("爸") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("爷") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("爹") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("伯") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("叔") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("舅") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("公")
                //        ))
                //    {
                //        haveError = true;
                //    }
                //    else
                //    {
                //        if (biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("母") ||
                //            biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("妈") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("奶") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("娘") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("姨") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("婆") ||
                //        biiBaseInfosInputer.tbxGuardianRelation.Text.Contains("婶"))
                //        {
                //            haveError = true;
                //        }
                //    }

                //    if (haveError)
                //    {
                //        LMessageBox.Show("　　监护人身份证号读取的性别与填写的“与学生关系”不一致！", Globals.AppName,
                //             MessageBoxButton.OK, MessageBoxImage.Error);
                //        e.Cancel = true;
                //        return;
                //    }
                //}
                //else
                //{
                //    LMessageBox.Show("　　无法从监护人身份证号中读取性别！", Globals.AppName,
                //     MessageBoxButton.OK, MessageBoxImage.Error);
                //    e.Cancel = true;
                //    return;
                //}
                //#endregion

                if (biiBaseInfosInputer.ErrorExist)
                {
                    LMessageBox.Show("　　当前页面中有必填项未填写，或者填写的数据有错误。\r\n　　请修正后重试！", Globals.AppName,
                         MessageBoxButton.OK, MessageBoxImage.Error);
                    e.Cancel = true;
                    return;
                }

                var errText = biiBaseInfosInputer.InfosEntry.BlankErrorText;
                if (string.IsNullOrWhiteSpace(errText) == false)
                {
                    LMessageBox.Show($"　　当前页面中有必填项未填写，或者填写的数据有错误。\r\n\r\n{errText}\r\n\r\n　　请修正后重试！",
                        Globals.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
                    e.Cancel = true;
                    return;
                }
            }
        }

        private void studentInfosInputWizard_Finish(object sender, RoutedEventArgs e)
        {
            if (biiBaseInfosInputer.ErrorExist)
            {
                LMessageBox.Show("　　【学生基本信息】页面中有必填项未填写，或者填写的数据有错误。\r\n　　请修正后重试！", Globals.AppName,
                     MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (string.IsNullOrWhiteSpace(biiBaseInfosInputer.InfosEntry.BlankErrorText) == false)
            {
                LMessageBox.Show("　　【学生基本信息】页面中有必填项未填写，或者填写的数据有错误。\r\n　　请修正后重试！", Globals.AppName,
                     MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (studentInfosInputWizard.CurrentPage == wpBaseInfosInput)
            {
                if (biiEcnomicInfosInputer.ErrorExist)
                {
                    var result = LMessageBox.Show("　　【学生家庭经济状况】页面中有必填项未填写，或者填写的数据有错误。\r\n\r\n　　该同学确实【没有意向】申请助学金？\r\n\r\n　　如果该同学有意向申请助学金，清按【否】并输入家庭经济状况。", Globals.AppName,
                             MessageBoxButton.YesNo, MessageBoxImage.Warning);
                    if (result != MessageBoxResult.Yes) return;
                }

                var errText = biiEcnomicInfosInputer.InfosEntry.BlankErrorText;
                if (string.IsNullOrWhiteSpace(errText) == false)
                {
                    var result = LMessageBox.Show($"　　【学生家庭经济状况】页面中有必填项未填写，或者填写的数据有错误。\r\n\r\n{errText}\r\n\r\n　　该同学确实【没有意向】申请助学金？\r\n\r\n　　如果该同学有意向申请助学金，清按【否】并输入家庭经济状况。", Globals.AppName,
                             MessageBoxButton.YesNo, MessageBoxImage.Warning);
                    if (result != MessageBoxResult.Yes) return;
                }
            }

            //因县局尚未回复到底使用哪家银行的卡
            //所以暂时没有办法确定银行卡相关信息
            //if (biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerRelationship == "本人")
            //{
            //    if (biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerName != biiBaseInfosInputer.InfosEntry.StudentName)
            //    {
            //        LMessageBox.Show("　　【持卡人】为学生本人，但【持卡人姓名】却不是【学生姓名】！", Globals.AppName,
            //         MessageBoxButton.OK, MessageBoxImage.Error);
            //        return;
            //    }

            //    if (biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerCid != biiBaseInfosInputer.InfosEntry.StudentCid)
            //    {
            //        LMessageBox.Show("　　【持卡人】为学生本人，但【持卡人身份证号】却不是【学生身份证号】！", Globals.AppName,
            //            MessageBoxButton.OK, MessageBoxImage.Error);
            //        return;
            //    }
            //}

            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbFilePath + ";Password=DyBj#PpBb;"))
            {
                connection.Open();

                var sqlQuery = $"select * from StudentInfos where StudentCid=\"{biiBaseInfosInputer.InfosEntry.StudentCid}\"";
                SQLiteCommand command = connection.CreateCommand();
                command.CommandText = sqlQuery;
                SQLiteDataReader reader = command.ExecuteReader();

                string sqlCommandText;

                if (reader.Read() && reader["StudentCid"].ToString().ToUpper() == biiBaseInfosInputer.InfosEntry.StudentCid.ToUpper())
                {
                    var msgresult = LMessageBox.Show($"数据库中已存在身份证号为【{biiBaseInfosInputer.InfosEntry.StudentCid}】的学生信息，要覆盖吗？",
                        Globals.AppName, MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (msgresult != MessageBoxResult.Yes) return;

                    reader.Close();

                    sqlCommandText =
                        "update StudentInfos set "
                        + "StudentGrade=@StudentGrade,"
                        + "StudentClass=@StudentClass,"
                        + "StudentNumber=@StudentNumber,"
                        + "StudentName=@StudentName,"
                        + "StudentOldName=@StudentOldName,"
                        //+ "StudentCid=@StudentCid,"
                        + "SchoolRoll=@SchoolRoll,"
                        + "AdmissionDate=@AdmissionDate,"
                        + "StudentNation=@StudentNation,"
                        + "PoliticalStatus=@PoliticalStatus,"
                        + "NativePlace=@NativePlace,"
                        + "ResidencePlace=@ResidencePlace,"
                        + "ResidenceType=@ResidenceType,"
                        + "StudentHealthCondition=@StudentHealthCondition,"
                        + "StudentCurrentPlace=@StudentCurrentPlace,"
                        + "StudentDetailAddress=@StudentDetailAddress,"
                        + "StudentEmail=@StudentEmail,"
                        + "PostCode=@PostCode,"
                        + "StudentPhoneCode=@StudentPhoneCode,"
                        + "GuardianName=@GuardianName,"
                        + "GuardianCompany=@GuardianCompany,"
                        + "GuardianCid=@GuardianCid,"
                        + "GuardianRelation=@GuardianRelation,"
                        + "GuardianPhoneCode=@GuardianPhoneCode,"
                        + "SavingCardNumber=@SavingCardNumber,"
                        + "SavingCardBankName=@SavingCardBankName,"
                        + "SavingCardOwnerName=@SavingCardOwnerName,"
                        + "SavingCardOwnerRelationship=@SavingCardOwnerRelationship,"
                        + "SavingCardOwnerCid=@SavingCardOwnerCid,"
                        + "IsFiveGuaranteesFamily=@IsFiveGuaranteesFamily,"
                        + "IsBasicLivingAllowances=@IsBasicLivingAllowances,"
                        + "IsSingleParentChild=@IsSingleParentChild,"
                        + "IsOrphan=@IsOrphan,"
                        + "IsDeformityParentsChild=@IsDeformityParentsChild,"
                        + "StudentDeformityStatus=@StudentDeformityStatus,"
                        + "IsParentsCanNotWork=@IsParentsCanNotWork,"
                        + "IsSeriousIllnessInTheFamily=@IsSeriousIllnessInTheFamily,"
                        + "IsArmyOrSpecialCaredChild=@IsArmyOrSpecialCaredChild,"
                        + "AnnualHouseholdIncome=@AnnualHouseholdIncome,"
                        + "SourceOfFamilyIncome=@SourceOfFamilyIncome,"
                        + "IsSufferFromNaturalDisasters=@IsSufferFromNaturalDisasters,"
                        + "NaturalDisastersDiscription=@NaturalDisastersDiscription,"
                        + "IsUnexpectedAccidentHappened=@IsUnexpectedAccidentHappened,"
                        + "UnexpectedAccidentDiscription=@UnexpectedAccidentDiscription,"
                        + "AmountOfDebt=@AmountOfDebt,"
                        + "DebtReson=@DebtReson,"
                        + "FamilyMembersCount=@FamilyMembersCount,"
                        + "SupportPersonsCount=@SupportPersonsCount,"
                        + "IsRegistedPoorFamily=@IsRegistedPoorFamily,"
                        + "IsRegistedBasicLivingAllowances=@IsRegistedBasicLivingAllowances,"
                        + "OtherInfosFromCivilDepartment=@OtherInfosFromCivilDepartment,"
                        + "LaborCountOfFamily=@LaborCountOfFamily,"
                        + "UnemployedCountOfFamily=@UnemployedCountOfFamily,"
                        + "OtherInfos=@OtherInfos"
                        + $" where StudentCid=\"{biiBaseInfosInputer.InfosEntry.StudentCid.ToUpper()}\";";

                    command.Parameters.Add(new SQLiteParameter("StudentGrade", biiBaseInfosInputer.InfosEntry.StudentGrade));
                    command.Parameters.Add(new SQLiteParameter("StudentClass", biiBaseInfosInputer.InfosEntry.StudentClass));
                    command.Parameters.Add(new SQLiteParameter("StudentNumber", biiBaseInfosInputer.InfosEntry.StudentNumber));
                    command.Parameters.Add(new SQLiteParameter("StudentName", biiBaseInfosInputer.InfosEntry.StudentName));
                    command.Parameters.Add(new SQLiteParameter("StudentOldName", biiBaseInfosInputer.InfosEntry.StudentOldName));
                    //command.Parameters.Add(new SQLiteParameter("StudentCid", biiBaseInfosInputer.InfosEntry.StudentCid));
                    command.Parameters.Add(new SQLiteParameter("SchoolRoll", biiBaseInfosInputer.InfosEntry.SchoolRoll));
                    command.Parameters.Add(new SQLiteParameter("AdmissionDate", biiBaseInfosInputer.InfosEntry.AdmissionDate));
                    command.Parameters.Add(new SQLiteParameter("StudentNation", biiBaseInfosInputer.InfosEntry.StudentNation));
                    command.Parameters.Add(new SQLiteParameter("PoliticalStatus", biiBaseInfosInputer.InfosEntry.PoliticalStatus));
                    command.Parameters.Add(new SQLiteParameter("NativePlace", biiBaseInfosInputer.InfosEntry.NativePlace));
                    command.Parameters.Add(new SQLiteParameter("ResidencePlace", biiBaseInfosInputer.InfosEntry.ResidencePlace));
                    command.Parameters.Add(new SQLiteParameter("ResidenceType", biiBaseInfosInputer.InfosEntry.ResidenceType));
                    command.Parameters.Add(new SQLiteParameter("StudentHealthCondition", biiBaseInfosInputer.InfosEntry.StudentHealthCondition));
                    command.Parameters.Add(new SQLiteParameter("StudentCurrentPlace", biiBaseInfosInputer.InfosEntry.StudentCurrentPlace));
                    command.Parameters.Add(new SQLiteParameter("StudentDetailAddress", biiBaseInfosInputer.InfosEntry.StudentDetailAddress));
                    command.Parameters.Add(new SQLiteParameter("StudentEmail", biiBaseInfosInputer.InfosEntry.StudentEmail));
                    command.Parameters.Add(new SQLiteParameter("PostCode", biiBaseInfosInputer.InfosEntry.PostCode));
                    command.Parameters.Add(new SQLiteParameter("StudentPhoneCode", biiBaseInfosInputer.InfosEntry.StudentPhoneCode));
                    command.Parameters.Add(new SQLiteParameter("GuardianName", biiBaseInfosInputer.InfosEntry.GuardianName));
                    command.Parameters.Add(new SQLiteParameter("GuardianCompany", biiBaseInfosInputer.InfosEntry.GuardianCompany));
                    command.Parameters.Add(new SQLiteParameter("GuardianCid", biiBaseInfosInputer.InfosEntry.GuardianCid));
                    command.Parameters.Add(new SQLiteParameter("GuardianRelation", biiBaseInfosInputer.InfosEntry.GuardianRelation));
                    command.Parameters.Add(new SQLiteParameter("GuardianPhoneCode", biiBaseInfosInputer.InfosEntry.GuardianPhoneCode));
                    command.Parameters.Add(new SQLiteParameter("SavingCardNumber", biiEcnomicInfosInputer.InfosEntry.SavingCardNumber));
                    command.Parameters.Add(new SQLiteParameter("SavingCardBankName", biiEcnomicInfosInputer.InfosEntry.SavingCardBankName));
                    command.Parameters.Add(new SQLiteParameter("SavingCardOwnerName", biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerName));
                    command.Parameters.Add(new SQLiteParameter("SavingCardOwnerRelationship", biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerRelationship));
                    command.Parameters.Add(new SQLiteParameter("SavingCardOwnerCid", biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerCid));
                    command.Parameters.Add(new SQLiteParameter("IsFiveGuaranteesFamily", biiEcnomicInfosInputer.InfosEntry.IsFiveGuaranteesFamily));
                    command.Parameters.Add(new SQLiteParameter("IsBasicLivingAllowances", biiEcnomicInfosInputer.InfosEntry.IsBasicLivingAllowances));
                    command.Parameters.Add(new SQLiteParameter("IsSingleParentChild", biiEcnomicInfosInputer.InfosEntry.IsSingleParentChild));
                    command.Parameters.Add(new SQLiteParameter("IsOrphan", biiEcnomicInfosInputer.InfosEntry.IsOrphan));
                    command.Parameters.Add(new SQLiteParameter("IsDeformityParentsChild", biiEcnomicInfosInputer.InfosEntry.IsDeformityParentsChild));
                    command.Parameters.Add(new SQLiteParameter("StudentDeformityStatus", biiEcnomicInfosInputer.InfosEntry.StudentDeformityStatus));
                    command.Parameters.Add(new SQLiteParameter("IsParentsCanNotWork", biiEcnomicInfosInputer.InfosEntry.IsParentsCanNotWork));
                    command.Parameters.Add(new SQLiteParameter("IsSeriousIllnessInTheFamily", biiEcnomicInfosInputer.InfosEntry.IsSeriousIllnessInTheFamily));
                    command.Parameters.Add(new SQLiteParameter("IsArmyOrSpecialCaredChild", biiEcnomicInfosInputer.InfosEntry.IsArmyOrSpecialCaredChild));
                    command.Parameters.Add(new SQLiteParameter("AnnualHouseholdIncome", biiEcnomicInfosInputer.InfosEntry.AnnualHouseholdIncome));
                    command.Parameters.Add(new SQLiteParameter("SourceOfFamilyIncome", biiEcnomicInfosInputer.InfosEntry.SourceOfFamilyIncome));
                    command.Parameters.Add(new SQLiteParameter("IsSufferFromNaturalDisasters", biiEcnomicInfosInputer.InfosEntry.IsSufferFromNaturalDisasters));
                    command.Parameters.Add(new SQLiteParameter("NaturalDisastersDiscription", biiEcnomicInfosInputer.InfosEntry.NaturalDisastersDiscription));
                    command.Parameters.Add(new SQLiteParameter("IsUnexpectedAccidentHappened", biiEcnomicInfosInputer.InfosEntry.IsUnexpectedAccidentHappened));
                    command.Parameters.Add(new SQLiteParameter("UnexpectedAccidentDiscription", biiEcnomicInfosInputer.InfosEntry.UnexpectedAccidentDiscription));
                    command.Parameters.Add(new SQLiteParameter("AmountOfDebt", biiEcnomicInfosInputer.InfosEntry.AmountOfDebt));
                    command.Parameters.Add(new SQLiteParameter("DebtReson", biiEcnomicInfosInputer.InfosEntry.DebtReson));
                    command.Parameters.Add(new SQLiteParameter("FamilyMembersCount", biiEcnomicInfosInputer.InfosEntry.FamilyMembersCount));
                    command.Parameters.Add(new SQLiteParameter("SupportPersonsCount", biiEcnomicInfosInputer.InfosEntry.SupportPersonsCount));
                    command.Parameters.Add(new SQLiteParameter("IsRegistedPoorFamily", biiEcnomicInfosInputer.InfosEntry.IsRegistedPoorFamily));
                    command.Parameters.Add(new SQLiteParameter("IsRegistedBasicLivingAllowances", biiEcnomicInfosInputer.InfosEntry.IsRegistedBasicLivingAllowances));
                    command.Parameters.Add(new SQLiteParameter("OtherInfosFromCivilDepartment", biiEcnomicInfosInputer.InfosEntry.OtherInfosFromCivilDepartment));
                    command.Parameters.Add(new SQLiteParameter("LaborCountOfFamily", biiEcnomicInfosInputer.InfosEntry.LaborCountOfFamily));
                    command.Parameters.Add(new SQLiteParameter("UnemployedCountOfFamily", biiEcnomicInfosInputer.InfosEntry.UnemployedCountOfFamily));
                    command.Parameters.Add(new SQLiteParameter("OtherInfos", biiEcnomicInfosInputer.InfosEntry.OtherInfos));

                    command.CommandText = sqlCommandText;
                    var result = command.ExecuteNonQuery();
                    if (result == 1)
                    {
                        LMessageBox.Show("更新一条记录");
                    }
                }
                else
                {
                    sqlCommandText =
                        "insert into StudentInfos values("
                        + "@id, "
                        + "@StudentGrade, "
                        + "@StudentClass, "
                        + "@StudentNumber, "
                        + "@StudentName, "
                        + "@StudentOldName, "
                        + "@StudentCid, "
                        + "@SchoolRoll, "
                        + "@AdmissionDate, "
                        + "@StudentNation, "
                        + "@PoliticalStatus, "
                        + "@NativePlace, "
                        + "@ResidencePlace, "
                        + "@ResidenceType, "
                        + "@StudentHealthCondition, "
                        + "@StudentCurrentPlace, "
                        + "@StudentDetailAddress, "
                        + "@StudentEmail, "
                        + "@PostCode, "
                        + "@StudentPhoneCode, "
                        + "@GuardianName, "
                        + "@GuardianCompany, "
                        + "@GuardianCid, "
                        + "@GuardianRelation, "
                        + "@GuardianPhoneCode, "
                        + "@SavingCardNumber, "
                        + "@SavingCardBankName, "
                        + "@SavingCardOwnerName, "
                        + "@SavingCardOwnerRelationship, "
                        + "@SavingCardOwnerCid, "
                        + "@IsFiveGuaranteesFamily, "
                        + "@IsBasicLivingAllowances, "
                        + "@IsSingleParentChild, "
                        + "@IsOrphan, "
                        + "@IsDeformityParentsChild, "
                        + "@StudentDeformityStatus, "
                        + "@IsParentsCanNotWork, "
                        + "@IsSeriousIllnessInTheFamily, "
                        + "@IsArmyOrSpecialCaredChild, "
                        + "@AnnualHouseholdIncome, "
                        + "@SourceOfFamilyIncome, "
                        + "@IsSufferFromNaturalDisasters, "
                        + "@NaturalDisastersDiscription, "
                        + "@IsUnexpectedAccidentHappened, "
                        + "@UnexpectedAccidentDiscription, "
                        + "@AmountOfDebt, "
                        + "@DebtReson, "
                        + "@FamilyMembersCount, "
                        + "@SupportPersonsCount, "
                        + "@IsRegistedPoorFamily, "
                        + "@IsRegistedBasicLivingAllowances, "
                        + "@OtherInfosFromCivilDepartment, "
                        + "@LaborCountOfFamily, "
                        + "@UnemployedCountOfFamily, "
                        + "@OtherInfos"
                        + ")";

                    var insertResult = dbManager.InsertRecord(sqlCommandText, new SQLiteParameter[] {
                        new SQLiteParameter("@id",null),
                        new SQLiteParameter("@StudentGrade",biiBaseInfosInputer.InfosEntry.StudentGrade),
                        new SQLiteParameter("@StudentClass",biiBaseInfosInputer.InfosEntry.StudentClass),
                        new SQLiteParameter("@StudentNumber",biiBaseInfosInputer.InfosEntry.StudentNumber),
                        new SQLiteParameter("@StudentName",biiBaseInfosInputer.InfosEntry.StudentName),
                        new SQLiteParameter("@StudentOldName",biiBaseInfosInputer.InfosEntry.StudentOldName),
                        new SQLiteParameter("@StudentCid",biiBaseInfosInputer.InfosEntry.StudentCid),
                        new SQLiteParameter("@SchoolRoll",biiBaseInfosInputer.InfosEntry.SchoolRoll),
                        new SQLiteParameter("@AdmissionDate",biiBaseInfosInputer.InfosEntry.AdmissionDate),
                        new SQLiteParameter("@StudentNation",biiBaseInfosInputer.InfosEntry.StudentNation),
                        new SQLiteParameter("@PoliticalStatus",biiBaseInfosInputer.InfosEntry.PoliticalStatus),
                        new SQLiteParameter("@NativePlace",biiBaseInfosInputer.InfosEntry.NativePlace.ToString()),                  //除地址外，其余均为string型。
                        new SQLiteParameter("@ResidencePlace",biiBaseInfosInputer.InfosEntry.ResidencePlace.ToString()),            //除地址外，其余均为string型。
                        new SQLiteParameter("@ResidenceType",biiBaseInfosInputer.InfosEntry.ResidenceType),
                        new SQLiteParameter("@StudentHealthCondition",biiBaseInfosInputer.InfosEntry.StudentHealthCondition),
                        new SQLiteParameter("@StudentCurrentPlace",biiBaseInfosInputer.InfosEntry.StudentCurrentPlace.ToString()),  //除地址外，其余均为string型。
                        new SQLiteParameter("@StudentDetailAddress",biiBaseInfosInputer.InfosEntry.StudentDetailAddress),
                        new SQLiteParameter("@StudentEmail",biiBaseInfosInputer.InfosEntry.StudentEmail),
                        new SQLiteParameter("@PostCode",biiBaseInfosInputer.InfosEntry.PostCode),
                        new SQLiteParameter("@StudentPhoneCode",biiBaseInfosInputer.InfosEntry.StudentPhoneCode),
                        new SQLiteParameter("@GuardianName",biiBaseInfosInputer.InfosEntry.GuardianName),
                        new SQLiteParameter("@GuardianCompany",biiBaseInfosInputer.InfosEntry.GuardianCompany),
                        new SQLiteParameter("@GuardianCid",biiBaseInfosInputer.InfosEntry.GuardianCid),
                        new SQLiteParameter("@GuardianRelation",biiBaseInfosInputer.InfosEntry.GuardianRelation),
                        new SQLiteParameter("@GuardianPhoneCode",biiBaseInfosInputer.InfosEntry.GuardianPhoneCode),
                        new SQLiteParameter("@SavingCardNumber",biiEcnomicInfosInputer.InfosEntry.SavingCardNumber),
                        new SQLiteParameter("@SavingCardBankName",biiEcnomicInfosInputer.InfosEntry.SavingCardBankName),
                        new SQLiteParameter("@SavingCardOwnerName",biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerName),
                        new SQLiteParameter("@SavingCardOwnerRelationship",biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerRelationship),
                        new SQLiteParameter("@SavingCardOwnerCid",biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerCid),
                        new SQLiteParameter("@IsFiveGuaranteesFamily",biiEcnomicInfosInputer.InfosEntry.IsFiveGuaranteesFamily),
                        new SQLiteParameter("@IsBasicLivingAllowances",biiEcnomicInfosInputer.InfosEntry.IsBasicLivingAllowances),
                        new SQLiteParameter("@IsSingleParentChild",biiEcnomicInfosInputer.InfosEntry.IsSingleParentChild),
                        new SQLiteParameter("@IsOrphan",biiEcnomicInfosInputer.InfosEntry.IsOrphan),
                        new SQLiteParameter("@IsDeformityParentsChild",biiEcnomicInfosInputer.InfosEntry.IsDeformityParentsChild),
                        new SQLiteParameter("@StudentDeformityStatus",biiEcnomicInfosInputer.InfosEntry.StudentDeformityStatus),
                        new SQLiteParameter("@IsParentsCanNotWork",biiEcnomicInfosInputer.InfosEntry.IsParentsCanNotWork),
                        new SQLiteParameter("@IsSeriousIllnessInTheFamily",biiEcnomicInfosInputer.InfosEntry.IsSeriousIllnessInTheFamily),
                        new SQLiteParameter("@IsArmyOrSpecialCaredChild",biiEcnomicInfosInputer.InfosEntry.IsArmyOrSpecialCaredChild),
                        new SQLiteParameter("@AnnualHouseholdIncome",biiEcnomicInfosInputer.InfosEntry.AnnualHouseholdIncome),
                        new SQLiteParameter("@SourceOfFamilyIncome",biiEcnomicInfosInputer.InfosEntry.SourceOfFamilyIncome),
                        new SQLiteParameter("@IsSufferFromNaturalDisasters",biiEcnomicInfosInputer.InfosEntry.IsSufferFromNaturalDisasters),
                        new SQLiteParameter("@NaturalDisastersDiscription",biiEcnomicInfosInputer.InfosEntry.NaturalDisastersDiscription),
                        new SQLiteParameter("@IsUnexpectedAccidentHappened",biiEcnomicInfosInputer.InfosEntry.IsUnexpectedAccidentHappened),
                        new SQLiteParameter("@UnexpectedAccidentDiscription",biiEcnomicInfosInputer.InfosEntry.UnexpectedAccidentDiscription),
                        new SQLiteParameter("@AmountOfDebt",biiEcnomicInfosInputer.InfosEntry.AmountOfDebt),
                        new SQLiteParameter("@DebtReson",biiEcnomicInfosInputer.InfosEntry.DebtReson),
                        new SQLiteParameter("@FamilyMembersCount",biiEcnomicInfosInputer.InfosEntry.FamilyMembersCount),
                        new SQLiteParameter("@SupportPersonsCount",biiEcnomicInfosInputer.InfosEntry.SupportPersonsCount),
                        new SQLiteParameter("@IsRegistedPoorFamily",biiEcnomicInfosInputer.InfosEntry.IsRegistedPoorFamily),
                        new SQLiteParameter("@IsRegistedBasicLivingAllowances",biiEcnomicInfosInputer.InfosEntry.IsRegistedBasicLivingAllowances),
                        new SQLiteParameter("@OtherInfosFromCivilDepartment",biiEcnomicInfosInputer.InfosEntry.OtherInfosFromCivilDepartment),
                        new SQLiteParameter("@LaborCountOfFamily",biiEcnomicInfosInputer.InfosEntry.LaborCountOfFamily),
                        new SQLiteParameter("@UnemployedCountOfFamily",biiEcnomicInfosInputer.InfosEntry.UnemployedCountOfFamily),
                        new SQLiteParameter("@OtherInfos",biiEcnomicInfosInputer.InfosEntry.OtherInfos),
                    });

                    if (insertResult == 1)
                    {
                        LMessageBox.Show("添加一条新记录");
                        studentInfosInputWizard.CurrentPage = wpBaseInfosInput;
                    }
                }
            }

            var previewGradeIndex = biiBaseInfosInputer.cmbStudentGrade.SelectedIndex;
            var previewClassText = biiBaseInfosInputer.tbxStudentClass.Text;
            var previewClassNumberText = biiBaseInfosInputer.tbxStudentNumber.Text;

            //存入数据库后初始化输入界面。
            biiBaseInfosInputer.ClearFields();
            biiEcnomicInfosInputer.ClearFields();

            biiBaseInfosInputer.cmbStudentGrade.SelectedIndex = previewGradeIndex;
            biiBaseInfosInputer.tbxStudentClass.Text = previewClassText;

            int num;
            if (int.TryParse(previewClassNumberText, out num))
            {
                biiBaseInfosInputer.tbxStudentNumber.Text = (num + 1).ToString();
            }
        }

        private void miLodeDataTable_Click(object sender, RoutedEventArgs e)
        {
            LoadView(dataGrid, "select * from StudentInfos");
        }

        public void LoadView(ItemsControl control, string commandText)
        {
            try
            {
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbFilePath + ";Password=DyBj#PpBb;"))
                {
                    connection.Open();
                    using (SQLiteCommand command = new SQLiteCommand(commandText, connection))
                    {
                        using (SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(command))
                        {
                            DataTable dataTable = new DataTable();
                            dataAdapter.Fill(dataTable);
                            control.ItemsSource = dataTable.AsDataView();
                            tbRecordsCount.Text = $"当前共有 {dataTable.Rows.Count} 条记录！";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnSendDatabaseToDesktop_Click(object sender, RoutedEventArgs e)
        {
            var desktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
            if (desktopPath.EndsWith("\\") == false)
                desktopPath += "\\";

            var result = InputBox.Show(Globals.AppName, "请输入班级名：", "", true);
            if (string.IsNullOrWhiteSpace(result)) return;

            var now = System.DateTime.Now;
            System.IO.File.Copy(dbManager.DataBaseFilePath,
                desktopPath + result + "_学生信息_" + now.ToShortDateString().Replace("/", "-") + "_" + now.ToShortTimeString().Replace(":", "-") + ".db");
            var messageBoxResult = LMessageBox.Show("已将数据库文件复制到桌面。要打开文件夹吗？",
                Globals.AppName, MessageBoxButton.YesNo, MessageBoxImage.Information);
            if (messageBoxResult == MessageBoxResult.Yes)
            {
                System.Diagnostics.Process.Start("explorer.exe", desktopPath);
            }
        }

        private void miEditSelectedRow_Click(object sender, RoutedEventArgs e)
        {
            var row = dataGrid.SelectedItem as DataRowView;
            if (row == null)
            {
                LMessageBox.Show("请选中要编辑的行。", Globals.AppName, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            var cid = row["StudentCid"].ToString();

            if (string.IsNullOrWhiteSpace(cid))
            {
                LMessageBox.Show("该行身份证号为空白，无法编辑。", Globals.AppName, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            var sqlQuery = $"select * from StudentInfos where StudentCid=\"{cid}\"";

            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbFilePath + ";Password=DyBj#PpBb;"))
            {
                connection.Open();

                SQLiteCommand command = connection.CreateCommand();
                command.CommandText = sqlQuery;
                SQLiteDataReader reader = command.ExecuteReader();

                DataTable dTable = new DataTable();
                dTable.Load(reader);

                if (dTable.Rows.Count > 0)
                {
                    biiBaseInfosInputer.InfosEntry.StudentGrade = dTable.Rows[0]["StudentGrade"].ToString();
                    biiBaseInfosInputer.InfosEntry.StudentClass = dTable.Rows[0]["StudentClass"].ToString();
                    biiBaseInfosInputer.InfosEntry.StudentNumber = dTable.Rows[0]["StudentNumber"].ToString();
                    biiBaseInfosInputer.InfosEntry.StudentName = dTable.Rows[0]["StudentName"].ToString();
                    biiBaseInfosInputer.InfosEntry.StudentOldName = dTable.Rows[0]["StudentOldName"].ToString();
                    biiBaseInfosInputer.InfosEntry.StudentCid = dTable.Rows[0]["StudentCid"].ToString();
                    biiBaseInfosInputer.InfosEntry.SchoolRoll = dTable.Rows[0]["SchoolRoll"].ToString();
                    biiBaseInfosInputer.InfosEntry.AdmissionDate = dTable.Rows[0]["AdmissionDate"].ToString();
                    biiBaseInfosInputer.InfosEntry.StudentNation = dTable.Rows[0]["StudentNation"].ToString();
                    biiBaseInfosInputer.InfosEntry.PoliticalStatus = dTable.Rows[0]["PoliticalStatus"].ToString();
                    biiBaseInfosInputer.InfosEntry.NativePlace = dTable.Rows[0]["NativePlace"].ToString();
                    biiBaseInfosInputer.InfosEntry.ResidencePlace = dTable.Rows[0]["ResidencePlace"].ToString();
                    biiBaseInfosInputer.InfosEntry.ResidenceType = dTable.Rows[0]["ResidenceType"].ToString();
                    biiBaseInfosInputer.InfosEntry.StudentHealthCondition = dTable.Rows[0]["StudentHealthCondition"].ToString();
                    biiBaseInfosInputer.InfosEntry.StudentCurrentPlace = dTable.Rows[0]["StudentCurrentPlace"].ToString();
                    biiBaseInfosInputer.InfosEntry.StudentDetailAddress = dTable.Rows[0]["StudentDetailAddress"].ToString();
                    biiBaseInfosInputer.InfosEntry.StudentEmail = dTable.Rows[0]["StudentEmail"].ToString();
                    biiBaseInfosInputer.InfosEntry.PostCode = dTable.Rows[0]["PostCode"].ToString();
                    biiBaseInfosInputer.InfosEntry.StudentPhoneCode = dTable.Rows[0]["StudentPhoneCode"].ToString();
                    biiBaseInfosInputer.InfosEntry.GuardianName = dTable.Rows[0]["GuardianName"].ToString();
                    biiBaseInfosInputer.InfosEntry.GuardianCompany = dTable.Rows[0]["GuardianCompany"].ToString();
                    biiBaseInfosInputer.InfosEntry.GuardianCid = dTable.Rows[0]["GuardianCid"].ToString();
                    biiBaseInfosInputer.InfosEntry.GuardianRelation = dTable.Rows[0]["GuardianRelation"].ToString();
                    biiBaseInfosInputer.InfosEntry.GuardianPhoneCode = dTable.Rows[0]["GuardianPhoneCode"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.SavingCardNumber = dTable.Rows[0]["SavingCardNumber"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.SavingCardBankName = dTable.Rows[0]["SavingCardBankName"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerName = dTable.Rows[0]["SavingCardOwnerName"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerRelationship = dTable.Rows[0]["SavingCardOwnerRelationship"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.SavingCardOwnerCid = dTable.Rows[0]["SavingCardOwnerCid"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsFiveGuaranteesFamily = dTable.Rows[0]["IsFiveGuaranteesFamily"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsBasicLivingAllowances = dTable.Rows[0]["IsBasicLivingAllowances"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsSingleParentChild = dTable.Rows[0]["IsSingleParentChild"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsOrphan = dTable.Rows[0]["IsOrphan"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsDeformityParentsChild = dTable.Rows[0]["IsDeformityParentsChild"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.StudentDeformityStatus = dTable.Rows[0]["StudentDeformityStatus"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsParentsCanNotWork = dTable.Rows[0]["IsParentsCanNotWork"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsSeriousIllnessInTheFamily = dTable.Rows[0]["IsSeriousIllnessInTheFamily"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsArmyOrSpecialCaredChild = dTable.Rows[0]["IsArmyOrSpecialCaredChild"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.AnnualHouseholdIncome = dTable.Rows[0]["AnnualHouseholdIncome"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.SourceOfFamilyIncome = dTable.Rows[0]["SourceOfFamilyIncome"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsSufferFromNaturalDisasters = dTable.Rows[0]["IsSufferFromNaturalDisasters"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.NaturalDisastersDiscription = dTable.Rows[0]["NaturalDisastersDiscription"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsUnexpectedAccidentHappened = dTable.Rows[0]["IsUnexpectedAccidentHappened"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.UnexpectedAccidentDiscription = dTable.Rows[0]["UnexpectedAccidentDiscription"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.AmountOfDebt = dTable.Rows[0]["AmountOfDebt"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.DebtReson = dTable.Rows[0]["DebtReson"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.FamilyMembersCount = dTable.Rows[0]["FamilyMembersCount"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.SupportPersonsCount = dTable.Rows[0]["SupportPersonsCount"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsRegistedPoorFamily = dTable.Rows[0]["IsRegistedPoorFamily"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.IsRegistedBasicLivingAllowances = dTable.Rows[0]["IsRegistedBasicLivingAllowances"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.OtherInfosFromCivilDepartment = dTable.Rows[0]["OtherInfosFromCivilDepartment"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.LaborCountOfFamily = dTable.Rows[0]["LaborCountOfFamily"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.UnemployedCountOfFamily = dTable.Rows[0]["UnemployedCountOfFamily"].ToString();
                    biiEcnomicInfosInputer.InfosEntry.OtherInfos = dTable.Rows[0]["OtherInfos"].ToString();

                    tcMain.SelectedIndex = 1;
                    studentInfosInputWizard.CurrentPage = wpBaseInfosInput;
                }
            }
        }

        private void miCopyAll_Click(object sender, RoutedEventArgs e)
        {
            dataGrid.SelectionMode = DataGridSelectionMode.Extended;
            dataGrid.SelectAll();
            dataGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
            ApplicationCommands.Copy.Execute(null, dataGrid);
            dataGrid.SelectionMode = DataGridSelectionMode.Single;
            MessageBox.Show("已复制到剪贴板！");
        }
    }
}
